package com.hjm.admin.moule.view.fragment;

import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.gigamole.navigationtabstrip.NavigationTabStrip;
import com.hjm.admin.moule.R;
import com.hjm.admin.moule.view.activity.impl.MainActivity;
import com.hjm.admin.moule.view.base.BaseFragment;
import com.hjm.admin.moule.view.base.BaseViewPageAdapter;
import com.hjm.admin.moule.view.fragment.impl.ClassifyFragment;
import com.hjm.admin.moule.viewmodel.BaseViewModel;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;

public class BookClassifyFragment extends BaseFragment {
    @BindView(R.id.nts_classify)
    NavigationTabStrip mNtsClassfy;
    @BindView(R.id.vp_classify)
    ViewPager mVpClassify;


    String[] title = {"男生版", "女生版", "出版"};
    private List<Fragment> fragments;

    public static BookClassifyFragment newInstance() {
        return new BookClassifyFragment();
    }

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        return setContentView(container, R.layout.fragment_book_classify, new BaseViewModel(mContext));
    }

    @Override
    protected void initView() {
        fragments = new ArrayList<>();
        for (int i = 0; i < title.length; i++) {
            fragments.add(ClassifyFragment.newInstance(title[i]));
        }
        mVpClassify.setAdapter(new BaseViewPageAdapter(getChildFragmentManager(), title, fragments));
        mVpClassify.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

            }

            @Override
            public void onPageSelected(int position) {
                ((MainActivity) getActivity()).setLeftSlide(position == 0);
            }

            @Override
            public void onPageScrollStateChanged(int state) {

            }
        });
        mVpClassify.setOffscreenPageLimit(4);
        mNtsClassfy.setTitles(title);
        mNtsClassfy.setViewPager(mVpClassify);
    }
}
